package pcloud.client;


import pcloud.client.remoteservice.FileService;
import pcloud.client.scheduler.TaskScheduler;
import pcloud.client.util.FileResourceInfo;
import pcloud.client.util.FileSystemDB;
import pcloud.client.util.GlobalConfig;
import org.apache.log4j.Logger;
import pcloud.client.util.TreeDB;
import pcloud.client.watcher.FTPServerWatcher;
import pcloud.client.watcher.ServerWatcher;

public class TestCloudServerSyncOnce
{
	private static Logger logger = Logger.getLogger(TestCloudServerSyncOnce.class);

	public static void main(String[] args)
	{
		GlobalConfig.getInstance();
		TaskScheduler taskScheduler = new TaskScheduler();
		TreeDB<FileResourceInfo> localDB = new FileSystemDB<FileResourceInfo>();
		ServerWatcher serverWatcher = new FTPServerWatcher(taskScheduler,localDB);

		logger.info("before start remote service");
		FileService service = GlobalConfig.initRemoteService();
		if (service==null) {
			return;
		}

		taskScheduler.start();

		logger.info("before serverWatcher.run()");
		serverWatcher.testHandleServerChange();

		try {
			Thread.sleep(3000);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		
		GlobalConfig.releaseRemoteService();
		try {
			taskScheduler.stop();
			taskScheduler.getWorkingThread().join();
		} catch (InterruptedException e) {
			logger.error("wait scheduler thread failed! ");
		}
		logger.info("all tasks handled. ");
	}

}
